import {Classificationlist,Addclassification} from '@/api/http.js'
import { Message } from 'element-ui';
const state ={
  //分类列表
  Classificationlist:[]
};
const mutations={
//分类列表
CLASSIFICATION(state,Classificationlist){
  state.Classificationlist = Classificationlist
}
};
const actions ={
//分类列表
 async getClassificationlist({commit}){
 let request = await Classificationlist()
 console.log(request)
 if(request.status==200){
  commit('CLASSIFICATION',request.data)
 }
  },
  //添加分类
  async getAddclassification({commit},{name,pid}){
    if(name==''){
      Message({
      message: '分类名称 不能为空',
      type: 'warning'
    })
    }else{
  let request = await Addclassification({name,pid})
  console.log(request)
  if(request.status==201){
    Message({
      message: '创建分类成功',
      type: 'success'
    })
  }else{
    Message({
      message: '创建分类失败',
      type: 'warning'
    })
  }
    }

  }
};
const getters ={}
export default {
  state,
  mutations,
  actions,
  getters
}